package com.jye.rseven.user.serivce.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.jye.rseven.domain.Videos;
import com.jye.rseven.user.mapper.VideoMapper;
import com.jye.rseven.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class VideoServiceImpl implements VideoService {

    @Autowired
    VideoMapper videoMapper;


    @Override
    public int  saveVideo(Videos videos) {
        if(StringUtils.isEmpty(videos.getId())){
            //空的为保存
            try {
                videoMapper.addVideo(videos);
            } catch (Exception e) {
                return 0;
            }
            return 1;
        }else{
            //id不为空则修改
            try{
                videoMapper.updateVideo(videos);
            }catch (Exception e){
                return 0;
            }
            return 1;
        }
    }

    @Override
    public List<Videos> findAllVideos() {
        List<Videos> videosList = videoMapper.findAllVideos();
        return videosList;
    }

    @Override
    public Videos findVideoById(int id) {
        Videos videos = videoMapper.findVideoById(id);
        return videos;
    }

    @Override
    public List<Videos> findVideosByPIdAndStatus(int pId, int status) {
        List<Videos> videosList = videoMapper.findVideosByPIdAndStatus(pId, status);
        return videosList;
    }
}
